package com.yilin.tms.core.entity.order.dispatch;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.yilin.tms.core.commons.base.BaseDataEntity;
import com.yilin.tms.core.commons.annotation.Explain;
import com.yilin.tms.core.entity.order.goods.GoodsOrder;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;


/**
 * 派单类
 *
 * @author zhangjinyuan
 * @date 2022/10/28
 */
@Entity
@Table(name = "dispatch_order")
@TableName(value = "dispatch_order")
public class DispatchOrder extends BaseDataEntity {
    /**
     * 状态
     */
    public enum DispatchStatus {
        going(0, "进行中"),
        recycle(1, "回收站");
        @EnumValue
        public Integer index;
        public String name;

        DispatchStatus(Integer index, String name) {
            this.index = index;
            this.name = name;
        }
    }

    /**
     * 基础信息
     */
    @Explain("派单标题")
    @Column(name = "title")
    private String title;//自定义，如，派给XXX的货源
    @Explain("派单编号")
    @Column(name = "dispatch_order_no")
    private String dispatchOrderNo;
    @Explain("已派单次数")
    @Column(name = "dispatch_count")
    private Integer dispatchCount = 0;//已派单次数
    @Explain("上次派单时间")
    @Column(name = "last_dispatch_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date lastDispatchTime; //上次派单时间
    @Explain("派单状态")
    @Column(name = "dispatch_status")
    private DispatchStatus dispatchStatus;//派单状态
    /**
     * 货主信息
     */
    @Explain("组织id")
    @Column(name = "shipper_organize_id")
    private String shipperOrganizeId;
    @Explain("组织名称")
    @Column(name = "shipper_organize_name")
    private String shipperOrganizeName;
    @Explain("上级集团ID")
    @Column(name = "shipper_group_organize_id")
    private String shipperGroupOrganizeId;
    @Explain("上级集团名称")
    @Column(name = "shipper_group_organize_name")
    private String shipperGroupOrganizeName;
    /**
     * 车主信息
     */
    @Explain("组织id")
    @Column(name = "trucker_organize_id")
    private String truckerOrganizeId;
    @Explain("组织名称")
    @Column(name = "trucker_organize_name")
    private String truckerOrganizeName;
    /**
     * 运输需求
     */
    @Explain("需求车型ID")
    @Column(name = "truck_type_ids", columnDefinition = "TEXT")
    private String truckTypeIds;//多个车型逗号隔开
    @Explain("需求车型名称")
    @Column(name = "truck_type_names", columnDefinition = "TEXT")
    private String truckTypeNames;//多个车型逗号隔开
    @Explain("运输类型id")
    @Column(name = "transport_type_id")
    private String transportTypeId;
    @Explain("运输类型名称")
    @Column(name = "transport_type_name")
    private String transportTypeName;
    @Explain("运输代码")
    @Column(name = "transport_type_code")
    private String transportTypeCode;
    @Explain("总距离")
    @Column(name = "kilometer")
    private Double kilometer;//总距离 单位：km
    @Explain("预计总时间")
    @Column(name = "duration")
    private Integer duration; //预计时间 单位：秒
    @Explain("限制抢单范围")
    @Column(name = "limit_rob_scope")
    private GoodsOrder.LimitRobScope limitRobScope;
    @Explain("货源备注")
    @Column(name = "goods_remark")
    private String goodsRemark;
    @Explain("货物类型显示")
    @Column(name = "goods_type_name")
    private String goodsTypeName; //货物类型显示（用于在列表显示，货物列表第一个）
    /**
     * 货物计量
     */
    @Explain("运输总量")
    @Column(name = "shipper_total_measure")
    private Double shipperTotalMeasure;
    @Explain("单位")
    @Column(name = "measure_unit")
    private String measureUnit;//修改：单位放在货源，统一计量单位
    @Explain("总毛重")
    @Column(name = "total_gross_weight")
    private Double totalGrossWeight;
    /**
     * 费用统计/合计
     */
    @Explain("计价模式")
    @Column(name = "price_mode")
    private GoodsOrder.PriceMode priceMode;//
    @Explain("结算方式")
    @Column(name = "settlement_type")
    private GoodsOrder.SettlementType settlementType;
    @Explain("运输费")
    @Column(name = "shipper_transport_cost")
    private Double shipperTransportCost = 0D;//主费用: 司机运输费【前台显示】
    @Explain("附加费")
    @Column(name = "shipper_additional_cost")
    private Double shipperAdditionalCost = 0D;//3.装卸费等
    @Explain("附加费详情")
    @Column(name = "shipper_additional_details")
    private String shipperAdditionalDetails;
    @Explain("保单额度")
    @Column(name = "insured_amount")
    private Double insuredAmount = 0D;
    /**
     * 配置 会员设定
     */
    @Explain("是否整车")
    @Column(name = "full_load")
    private Boolean fullLoad = false;
    @Explain("撮合业务")
    @Column(name = "matching")
    private Boolean matching = false;
    @Explain("是否含税")
    @Column(name = "included_tax")
    private Boolean includedTax = false;
    @Explain("拒绝议价")
    @Column(name = "no_bargain")
    private Boolean noBargain = false;
    @Explain("自动审核")
    @Column(name = "auto_audit")
    private Boolean autoAudit = false;
    @Explain("是否开启电子围栏")
    @Column(name = "start_fence")
    private Boolean startFence = false;
    @Explain("需要装货拍照")
    @Column(name = "need_upload_shipping")
    private Boolean needUploadShipping = false;
    @Explain("自动发货")
    @Column(name = "auto_delivery")
    private Boolean autoDelivery = false;
    @Explain("需要回执拍照")
    @Column(name = "need_upload_receipt")
    private Boolean needUploadReceipt = false;
    @Explain("跳过收货确认")
    @Column(name = "skip_confirm_receipt")
    private Boolean skipConfirmReceipt = false;
    @Explain("手动清算")
    @Column(name = "hand_liquidation")
    private Boolean handLiquidation = false;//新增：默认自动清算，货主/平台决定是否需要手动清算，汇总计价货源 必须手动清算

    @Transient
    @Explain("货物节点List")
    @TableField(exist = false)
    private List<DispatchOrderNote> dispatchOrderNoteList = new ArrayList<>();

    public GoodsOrder transGoodsOrder() {
        GoodsOrder goodsOrder = new GoodsOrder();
        goodsOrder.setTruckTypeIds(getTruckTypeIds());
        goodsOrder.setTruckTypeNames(getTruckTypeNames());
        goodsOrder.setTransportTypeId(getTransportTypeId());
        goodsOrder.setTransportTypeName(getTransportTypeName());
        goodsOrder.setTransportTypeCode(getTransportTypeCode());
        goodsOrder.setKilometer(getKilometer());
        goodsOrder.setDuration(getDuration());
        goodsOrder.setLimitRobScope(getLimitRobScope());
        goodsOrder.setGoodsRemark(getGoodsRemark());
        goodsOrder.setGoodsTypeName(getGoodsTypeName());
        goodsOrder.setShipperTotalMeasure(getShipperTotalMeasure());
        goodsOrder.setMeasureUnit(getMeasureUnit());
        goodsOrder.setTotalGrossWeight(getTotalGrossWeight());
        goodsOrder.setPriceMode(getPriceMode());
        goodsOrder.setSettlementType(getSettlementType());
        goodsOrder.setShipperTransportCost(getShipperTransportCost());
        goodsOrder.setShipperAdditionalCost(getShipperAdditionalCost());
        goodsOrder.setInsuredAmount(getInsuredAmount());
        goodsOrder.setFullLoad(getFullLoad());
        goodsOrder.setMatching(getMatching());
        goodsOrder.setIncludedTax(getIncludedTax());
        goodsOrder.setNoBargain(getNoBargain());
        goodsOrder.setAutoAudit(getAutoAudit());
        goodsOrder.setStartFence(getStartFence());
        goodsOrder.setNeedUploadShipping(getNeedUploadShipping());
        goodsOrder.setAutoDelivery(getAutoDelivery());
        goodsOrder.setNeedUploadReceipt(getNeedUploadReceipt());
        goodsOrder.setSkipConfirmReceipt(getSkipConfirmReceipt());
        goodsOrder.setHandLiquidation(getHandLiquidation());
        return goodsOrder;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getDispatchOrderNo() {
        return dispatchOrderNo;
    }

    public void setDispatchOrderNo(String dispatchOrderNo) {
        this.dispatchOrderNo = dispatchOrderNo;
    }

    public Integer getDispatchCount() {
        return dispatchCount;
    }

    public void setDispatchCount(Integer dispatchCount) {
        this.dispatchCount = dispatchCount;
    }

    public Date getLastDispatchTime() {
        return lastDispatchTime;
    }

    public void setLastDispatchTime(Date lastDispatchTime) {
        this.lastDispatchTime = lastDispatchTime;
    }

    public DispatchStatus getDispatchStatus() {
        return dispatchStatus;
    }

    public void setDispatchStatus(DispatchStatus dispatchStatus) {
        this.dispatchStatus = dispatchStatus;
    }

    public String getShipperOrganizeId() {
        return shipperOrganizeId;
    }

    public void setShipperOrganizeId(String shipperOrganizeId) {
        this.shipperOrganizeId = shipperOrganizeId;
    }

    public String getShipperOrganizeName() {
        return shipperOrganizeName;
    }

    public void setShipperOrganizeName(String shipperOrganizeName) {
        this.shipperOrganizeName = shipperOrganizeName;
    }

    public String getShipperGroupOrganizeId() {
        return shipperGroupOrganizeId;
    }

    public void setShipperGroupOrganizeId(String shipperGroupOrganizeId) {
        this.shipperGroupOrganizeId = shipperGroupOrganizeId;
    }

    public String getShipperGroupOrganizeName() {
        return shipperGroupOrganizeName;
    }

    public void setShipperGroupOrganizeName(String shipperGroupOrganizeName) {
        this.shipperGroupOrganizeName = shipperGroupOrganizeName;
    }

    public String getTruckerOrganizeId() {
        return truckerOrganizeId;
    }

    public void setTruckerOrganizeId(String truckerOrganizeId) {
        this.truckerOrganizeId = truckerOrganizeId;
    }

    public String getTruckerOrganizeName() {
        return truckerOrganizeName;
    }

    public void setTruckerOrganizeName(String truckerOrganizeName) {
        this.truckerOrganizeName = truckerOrganizeName;
    }

    public String getTruckTypeIds() {
        return truckTypeIds;
    }

    public void setTruckTypeIds(String truckTypeIds) {
        this.truckTypeIds = truckTypeIds;
    }

    public String getTruckTypeNames() {
        return truckTypeNames;
    }

    public void setTruckTypeNames(String truckTypeNames) {
        this.truckTypeNames = truckTypeNames;
    }

    public String getTransportTypeId() {
        return transportTypeId;
    }

    public void setTransportTypeId(String transportTypeId) {
        this.transportTypeId = transportTypeId;
    }

    public String getTransportTypeName() {
        return transportTypeName;
    }

    public void setTransportTypeName(String transportTypeName) {
        this.transportTypeName = transportTypeName;
    }

    public String getTransportTypeCode() {
        return transportTypeCode;
    }

    public void setTransportTypeCode(String transportTypeCode) {
        this.transportTypeCode = transportTypeCode;
    }

    public Double getKilometer() {
        return kilometer;
    }

    public void setKilometer(Double kilometer) {
        this.kilometer = kilometer;
    }

    public Integer getDuration() {
        return duration;
    }

    public void setDuration(Integer duration) {
        this.duration = duration;
    }

    public GoodsOrder.LimitRobScope getLimitRobScope() {
        return limitRobScope;
    }

    public void setLimitRobScope(GoodsOrder.LimitRobScope limitRobScope) {
        this.limitRobScope = limitRobScope;
    }

    public String getGoodsRemark() {
        return goodsRemark;
    }

    public void setGoodsRemark(String goodsRemark) {
        this.goodsRemark = goodsRemark;
    }

    public String getGoodsTypeName() {
        return goodsTypeName;
    }

    public void setGoodsTypeName(String goodsTypeName) {
        this.goodsTypeName = goodsTypeName;
    }

    public Double getShipperTotalMeasure() {
        return shipperTotalMeasure;
    }

    public void setShipperTotalMeasure(Double shipperTotalMeasure) {
        this.shipperTotalMeasure = shipperTotalMeasure;
    }

    public String getMeasureUnit() {
        return measureUnit;
    }

    public void setMeasureUnit(String measureUnit) {
        this.measureUnit = measureUnit;
    }

    public Double getTotalGrossWeight() {
        return totalGrossWeight;
    }

    public void setTotalGrossWeight(Double totalGrossWeight) {
        this.totalGrossWeight = totalGrossWeight;
    }

    public GoodsOrder.PriceMode getPriceMode() {
        return priceMode;
    }

    public void setPriceMode(GoodsOrder.PriceMode priceMode) {
        this.priceMode = priceMode;
    }

    public GoodsOrder.SettlementType getSettlementType() {
        return settlementType;
    }

    public void setSettlementType(GoodsOrder.SettlementType settlementType) {
        this.settlementType = settlementType;
    }

    public Double getShipperTransportCost() {
        return shipperTransportCost;
    }

    public void setShipperTransportCost(Double shipperTransportCost) {
        this.shipperTransportCost = shipperTransportCost;
    }

    public Double getShipperAdditionalCost() {
        return shipperAdditionalCost;
    }

    public void setShipperAdditionalCost(Double shipperAdditionalCost) {
        this.shipperAdditionalCost = shipperAdditionalCost;
    }

    public String getShipperAdditionalDetails() {
        return shipperAdditionalDetails;
    }

    public void setShipperAdditionalDetails(String shipperAdditionalDetails) {
        this.shipperAdditionalDetails = shipperAdditionalDetails;
    }

    public Double getInsuredAmount() {
        return insuredAmount;
    }

    public void setInsuredAmount(Double insuredAmount) {
        this.insuredAmount = insuredAmount;
    }

    public Boolean getFullLoad() {
        return fullLoad;
    }

    public void setFullLoad(Boolean fullLoad) {
        this.fullLoad = fullLoad;
    }

    public Boolean getMatching() {
        return matching;
    }

    public void setMatching(Boolean matching) {
        this.matching = matching;
    }

    public Boolean getIncludedTax() {
        return includedTax;
    }

    public void setIncludedTax(Boolean includedTax) {
        this.includedTax = includedTax;
    }

    public Boolean getNoBargain() {
        return noBargain;
    }

    public void setNoBargain(Boolean noBargain) {
        this.noBargain = noBargain;
    }

    public Boolean getAutoAudit() {
        return autoAudit;
    }

    public void setAutoAudit(Boolean autoAudit) {
        this.autoAudit = autoAudit;
    }

    public Boolean getStartFence() {
        return startFence;
    }

    public void setStartFence(Boolean startFence) {
        this.startFence = startFence;
    }

    public Boolean getNeedUploadShipping() {
        return needUploadShipping;
    }

    public void setNeedUploadShipping(Boolean needUploadShipping) {
        this.needUploadShipping = needUploadShipping;
    }

    public Boolean getAutoDelivery() {
        return autoDelivery;
    }

    public void setAutoDelivery(Boolean autoDelivery) {
        this.autoDelivery = autoDelivery;
    }

    public Boolean getNeedUploadReceipt() {
        return needUploadReceipt;
    }

    public void setNeedUploadReceipt(Boolean needUploadReceipt) {
        this.needUploadReceipt = needUploadReceipt;
    }

    public Boolean getSkipConfirmReceipt() {
        return skipConfirmReceipt;
    }

    public void setSkipConfirmReceipt(Boolean skipConfirmReceipt) {
        this.skipConfirmReceipt = skipConfirmReceipt;
    }

    public Boolean getHandLiquidation() {
        return handLiquidation;
    }

    public void setHandLiquidation(Boolean handLiquidation) {
        this.handLiquidation = handLiquidation;
    }

    public List<DispatchOrderNote> getDispatchOrderNoteList() {
        return dispatchOrderNoteList;
    }

    public void setDispatchOrderNoteList(List<DispatchOrderNote> dispatchOrderNoteList) {
        this.dispatchOrderNoteList = dispatchOrderNoteList;
    }
}
